package extension.game.zone;

import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.exceptions.SFSException;
import com.smartfoxserver.v2.extensions.BaseServerEventHandler;
import extension.game.room.Game;
import java.util.LinkedList;
import java.util.List;

public class OnUserJoinRoom extends BaseServerEventHandler {
    
    @Override
    public void handleServerEvent(ISFSEvent event) throws SFSException {
        User user = (User) event.getParameter(SFSEventParam.USER);
        Room room = (Room) event.getParameter(SFSEventParam.ROOM);
        GameZoneExtension ext = (GameZoneExtension) getParentExtension();
        Response response = ext.getResponse();
        String groupName = RoomGroup.LEVEL1;
        List<Room> listRooms;
        if (room.getName().equals("The Lobby")) {
            groupName = (String) user.getProperty(Flag.GROUP_NAME);
            if (groupName == null || groupName.length() == 0) {
                groupName = RoomGroup.LEVEL1;
                user.setProperty(Flag.GROUP_NAME, RoomGroup.LEVEL1);
                listRooms = ext.getParentZone().getRoomListFromGroup(RoomGroup.LEVEL1);
            } else {
                listRooms = ext.getParentZone().getRoomListFromGroup(groupName);
            }
            ext.onJoinLobby(listRooms, groupName, user);

        }
    }
}
